package com.boot.security.server.utils.mffl;

import com.boot.security.server.dao.mffl.MfflUserDao;
import com.boot.security.server.model.mffl.MfflUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;

import java.math.BigDecimal;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.*;

public class ProjectUtil {

    @Autowired
    private MfflUserDao mfflUserDao;

    /**
     *获取随机数(整数)
     */
    public static String getStringRandom(int length) {
       Random random = new Random();
       StringBuilder code = new StringBuilder();
       for(int i = 0;i<length; i++){
           code.append(random.nextInt(10));
       }
        return code.toString();
    }

    /**
     *获取随机商户订单号（时间（到毫秒）+随机数）
     */
    public static String payMerchantNumber(){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHssSSS");
        String format = simpleDateFormat.format(new Date());
        format += getStringRandom(8);
        return format;
    }

    /**
     *获取随机用户名
     */
    public static String getRandomString(int length){
        String str = "mffl";
        str += getRandom(length);
        return str;
    }

    /**
     *计算两个double类型的数字相加
     * @param additionnumber
     * @param Augend
     * @return
     */
    public static BigDecimal addition(Double additionnumber,Double Augend){
        BigDecimal b1 = new BigDecimal(additionnumber.toString());
        BigDecimal b2 = new BigDecimal(Augend.toString());
        return b1.add(b2);
    }
    /**
     *计算两个double类型的数字相减
     * @param additionnumber
     * @param Augend
     * @return
     */
    public static BigDecimal subtract(Double additionnumber,Double Augend){
        BigDecimal b1 = new BigDecimal(additionnumber.toString());
        BigDecimal b2 = new BigDecimal(Augend.toString());
        return b1.subtract(b2);
    }

    //计算扣点
    /**
     *
     * @param money 金额
     * @param points 扣点比例
     * @return  扣点之后的金额
     */
    public static double Points(double money,double points){
        return money-(money*points);
    }

    //获取初始化时间
    public static Date getinitialTime(){
        long t1= System.currentTimeMillis();
        long t2 = Long.parseLong("3153600000000");
        Date date = new Date();
        date.setTime(t1+t2);
        return date;
    }

    /**
     * 获取随机数
     * @param length
     * @return
     */
    public static String getRandom(int length){
        String str="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        Random random=new Random();
        StringBuffer sb=new StringBuffer();
        for(int i=0;i<length;i++){
            int number=random.nextInt(62);
            sb.append(str.charAt(number));
        }
        return sb.toString();
    }

    /**
     * 获取图片所有尺寸集合
     * @param ImageUrl 图片路径
     * @return map集合返回三种尺寸
     */
    public static  Map<String,Object> imageUrlAll(String ImageUrl){
        String[] split = ImageUrl.split("/");
        String string = split[split.length - 1];
        String[] split1 = string.split("\\.");
        String string1 = split1[1];
        String imageUrlMed = "/"+split1[0]+"_med."+string1;
        String ImageUrlMin = "/"+split1[0]+"_min."+string1;
        String path = "";
        //完整路径
        for(int i = split.length-2; i > 0; i--){
            path = "/"+split[i]+path;
        }
        Map<String,Object> map = new HashMap<>();
        map.put("imageUrl",ImageUrl);
        map.put("imageUrlMed",path+imageUrlMed);
        map.put("imageUrlMin",path+ImageUrlMin);
        return map;
    }
}
